package cn.tedu.review;

import java.io.*;

/*本类用于回顾多种流对象的创建方式*/
public class CreateStream {
    public static void main(String[] args) {
        f1();//用于复习字节流对象的创建
        f2();//用于复习字节流对象的创建
    }
    //本方法用于复习字符流对象的创建
    private static void f2() {
        try {
            /*字符输入流创建方式*/
            //Reader in = new Reader();//抽象父级不可实例化
            //Reader in = new FileReader("");//这种多态的创建方式也可以
            Reader in1 = new FileReader(new File("")); //多态:前父后子
            FileReader in2 = new FileReader("");
            BufferedReader in3 = new BufferedReader(new FileReader(new File("")));
            BufferedReader in4 = new BufferedReader(new FileReader(""));

            /*字符输出流创建方式*/
            FileWriter out1 = new FileWriter(new File(""));
            FileWriter out2 = new FileWriter("");
            FileWriter out3 = new FileWriter(new File(""),true);
            FileWriter out4 = new FileWriter("",true);

            BufferedWriter out5 = new BufferedWriter(new FileWriter(new File("")));
            BufferedWriter out6 = new BufferedWriter(
                    new FileWriter(new File(""),true));
            BufferedWriter out7 = new BufferedWriter(new FileWriter("")); //new File = 字符串
            BufferedWriter out8 = new BufferedWriter(new FileWriter("",true));
        } /*catch (Exception e) {
            e.printStackTrace();
        }*/ catch (Exception e) {
            throw new RuntimeException(e);
        }


    }
    //本方法用于复习字节流对象的创建
    private static void f1() {
        try {
            /*复习字节输入流的创建方式*/
            /*InputStream in = new InputStream() { //类似: 抽象类的匿名内部类的格式写法
                @Override
                public int read() throws IOException {
                    return 0;
                }
            }*/
            //InputStream in = new InputStream();//会报错,抽象父级不可实例化
            //InputStream in = new FileInputStream("");//这种是多态的方式,也可以
            FileInputStream in1 = new FileInputStream(new File(""));  //调用read()
            FileInputStream in2 = new FileInputStream("");//直接给路径,不file
            BufferedInputStream in3 = new BufferedInputStream( //高效字节输入流
                    new FileInputStream(new File("")));
            BufferedInputStream in4 = new BufferedInputStream(
                    new FileInputStream(""));

            /*复习字节输出流的创建方式*/ //写出数据到文件: write()方法,有覆盖和追加的两种方式,//输出给哪一个文件?!
            //OutputStream out = new OutputStream();//抽象父级不可实例化,会报错
            //OutputStream out = new FileOutputStream("");//多态的写法也是可以的
            //FileOutputStream对象的四种创建方式
            FileOutputStream out1 = new FileOutputStream(new File(""));//覆盖输出  //write()
            FileOutputStream out2 = new FileOutputStream(new File(""),true);//追加输出
            FileOutputStream out3 = new FileOutputStream("");//覆盖输出
            FileOutputStream out4 = new FileOutputStream("",true);//追加输出

            //高效字节输出流//高效方式
            OutputStream out5 = new BufferedOutputStream(
                    new FileOutputStream(""));//覆盖输出
            BufferedOutputStream out6 = new BufferedOutputStream(
                    new FileOutputStream("",true));//追加输出
            BufferedOutputStream out7 = new BufferedOutputStream(
                    new FileOutputStream(new File(""),true));//追加输出
            BufferedOutputStream out8 = new BufferedOutputStream(
                    new FileOutputStream(new File(""),false));//覆盖输出 //多态思想+参数的套娃
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }/* catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }*/
    }}
